package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelForm;
import cn.wolfcode.trip.base.mapper.TravelFormMapper;
import cn.wolfcode.trip.base.service.ITravelFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TravelFormServiceImpl implements ITravelFormService {

    @Autowired
    private TravelFormMapper travelFormMapper;
    @Override
    public void save(TravelForm travelForm) {
        travelFormMapper.insert(travelForm);
    }

    @Override
    public void select(TravelForm travelForm) {
        TravelForm tf = travelFormMapper.selectByUserIdAndTraveId(travelForm);
        if (tf != null){
            throw new RuntimeException("取消旅行");
        }
    }

    @Override
    public void delete(TravelForm travelForm) {
        travelFormMapper.deleteByUserIdAndTraveId(travelForm);
    }
    //通过用户id查询到他所有的旅游单
    @Override
    public List<TravelForm> listAll(Long userId) {
        return travelFormMapper.selectByUserIdForList(userId);
    }
}
